package com.shfl.servermanage.logic.bean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;

public class SysReleaseLog implements Serializable {
    public static final Integer IS_DELETED = DeleteFlg.IS_DELETED.value();

    public static final Integer NOT_DELETED = DeleteFlg.NOT_DELETED.value();

    private Long id;

    private Long siteId;

    private Long serviceId;

    private Long executableFileId;

    private String executableFileVersion;

    private Long releaseTime;

    private Integer releaseStatus;

    private Integer deleteFlg;

    private Long creator;

    private String creatorName;

    private Date createDate;

    private Long operator;

    private String operatorName;

    private Date operateDate;

    private String siteShell;

    private static final long serialVersionUID = 1L;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getSiteId() {
        return siteId;
    }

    public void setSiteId(Long siteId) {
        this.siteId = siteId;
    }

    public Long getServiceId() {
        return serviceId;
    }

    public void setServiceId(Long serviceId) {
        this.serviceId = serviceId;
    }

    public Long getExecutableFileId() {
        return executableFileId;
    }

    public void setExecutableFileId(Long executableFileId) {
        this.executableFileId = executableFileId;
    }

    public String getExecutableFileVersion() {
        return executableFileVersion;
    }

    public void setExecutableFileVersion(String executableFileVersion) {
        this.executableFileVersion = executableFileVersion == null ? null : executableFileVersion.trim();
    }

    public Long getReleaseTime() {
        return releaseTime;
    }

    public void setReleaseTime(Long releaseTime) {
        this.releaseTime = releaseTime;
    }

    public Integer getReleaseStatus() {
        return releaseStatus;
    }

    public void setReleaseStatus(Integer releaseStatus) {
        this.releaseStatus = releaseStatus;
    }

    public void andLogicalDeleted(boolean deleted) {
        setDeleteFlg(deleted ? DeleteFlg.IS_DELETED.value() : DeleteFlg.NOT_DELETED.value());
    }

    public Integer getDeleteFlg() {
        return deleteFlg;
    }

    public void setDeleteFlg(Integer deleteFlg) {
        this.deleteFlg = deleteFlg;
    }

    public Long getCreator() {
        return creator;
    }

    public void setCreator(Long creator) {
        this.creator = creator;
    }

    public String getCreatorName() {
        return creatorName;
    }

    public void setCreatorName(String creatorName) {
        this.creatorName = creatorName == null ? null : creatorName.trim();
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public Long getOperator() {
        return operator;
    }

    public void setOperator(Long operator) {
        this.operator = operator;
    }

    public String getOperatorName() {
        return operatorName;
    }

    public void setOperatorName(String operatorName) {
        this.operatorName = operatorName == null ? null : operatorName.trim();
    }

    public Date getOperateDate() {
        return operateDate;
    }

    public void setOperateDate(Date operateDate) {
        this.operateDate = operateDate;
    }

    public String getSiteShell() {
        return siteShell;
    }

    public void setSiteShell(String siteShell) {
        this.siteShell = siteShell == null ? null : siteShell.trim();
    }

    public enum DeleteFlg {
        NOT_DELETED(new Integer("1"), "未删除"),
        IS_DELETED(new Integer("0"), "已删除");

        private final Integer value;

        private final String name;

        DeleteFlg(Integer value, String name) {
            this.value = value;
            this.name = name;
        }

        public Integer getValue() {
            return this.value;
        }

        public Integer value() {
            return this.value;
        }

        public String getName() {
            return this.name;
        }
    }

    public enum Column {
        id("id", "id", "BIGINT", false),
        siteId("site_id", "siteId", "BIGINT", false),
        serviceId("service_id", "serviceId", "BIGINT", false),
        executableFileId("executable_file_id", "executableFileId", "BIGINT", false),
        executableFileVersion("executable_file_version", "executableFileVersion", "VARCHAR", false),
        releaseTime("release_time", "releaseTime", "BIGINT", false),
        releaseStatus("release_status", "releaseStatus", "INTEGER", false),
        deleteFlg("delete_flg", "deleteFlg", "INTEGER", false),
        creator("creator", "creator", "BIGINT", false),
        creatorName("creator_name", "creatorName", "VARCHAR", false),
        createDate("create_date", "createDate", "TIMESTAMP", false),
        operator("operator", "operator", "BIGINT", false),
        operatorName("operator_name", "operatorName", "VARCHAR", false),
        operateDate("operate_date", "operateDate", "TIMESTAMP", false),
        siteShell("site_shell", "siteShell", "LONGVARCHAR", false);

        private static final String BEGINNING_DELIMITER = "\"";

        private static final String ENDING_DELIMITER = "\"";

        private final String column;

        private final boolean isColumnNameDelimited;

        private final String javaProperty;

        private final String jdbcType;

        public String value() {
            return this.column;
        }

        public String getValue() {
            return this.column;
        }

        public String getJavaProperty() {
            return this.javaProperty;
        }

        public String getJdbcType() {
            return this.jdbcType;
        }

        Column(String column, String javaProperty, String jdbcType, boolean isColumnNameDelimited) {
            this.column = column;
            this.javaProperty = javaProperty;
            this.jdbcType = jdbcType;
            this.isColumnNameDelimited = isColumnNameDelimited;
        }

        public String desc() {
            return this.getEscapedColumnName() + " DESC";
        }

        public String asc() {
            return this.getEscapedColumnName() + " ASC";
        }

        public static Column[] excludes(Column ... excludes) {
            ArrayList<Column> columns = new ArrayList<>(Arrays.asList(Column.values()));
            if (excludes != null && excludes.length > 0) {
                columns.removeAll(new ArrayList<>(Arrays.asList(excludes)));
            }
            return columns.toArray(new Column[]{});
        }

        public static Column[] all() {
            return Column.values();
        }

        public String getEscapedColumnName() {
            if (this.isColumnNameDelimited) {
                return new StringBuilder().append(BEGINNING_DELIMITER).append(this.column).append(ENDING_DELIMITER).toString();
            } else {
                return this.column;
            }
        }

        public String getAliasedEscapedColumnName() {
            return this.getEscapedColumnName();
        }
    }
}